<template>
    <el-dialog v-model="dialogVisible" title="上传文件" width="580" append-to-body :close-on-click-modal="false">
        <el-form ref="infoRef" :model="form" :rules="rules" label-width="100px">
            <div v-hasPermi="['report:showMoney']">
                <el-form-item label="收费金额" prop="payFee">
                    <el-input v-model="form.payFee" placeholder="请输入" clearable />
                </el-form-item>
                <el-form-item label="收费单位" prop="payCompany">
                    <el-input v-model="form.payCompany" placeholder="请输入" clearable />
                </el-form-item>
            </div>
            <el-form-item label="是否(3+2)" prop="istat">
                <el-select v-model="form.istat" placeholder="请选择">
                    <el-option :value="1" label="是"></el-option>
                    <el-option :value="0" label="否"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="签字人" prop="signUser">
                <el-input v-model="form.signUser" placeholder="请输入" clearable />
            </el-form-item>
            <el-form-item label="报告部分" prop="reportFileIds">
                <FileUpload v-model="form.reportFileIds" />
            </el-form-item>
            <el-form-item label="会计资料" prop="accountFileIds">
                <FileUpload v-model="form.accountFileIds" />
            </el-form-item>
            <el-form-item label="审计底稿" prop="workpaperFileIds">
                <FileUpload v-model="form.workpaperFileIds" />
            </el-form-item>
        </el-form>
        <template #footer>
            <div class="dialog-footer">
                <el-button class="tongyi-btn" @click="dialogVisible = false">取消</el-button>
                <el-button class="tongyi-btn" type="primary" @click="handleSubmit">确定</el-button>
            </div>
        </template>
    </el-dialog>
</template>

<script setup>
import { ElMessage } from "element-plus";
import { updateReport } from "@/api/report";
const { proxy } = getCurrentInstance();
const emits = defineEmits(["update:visible", "finish"]);
const props = defineProps({
    visible: {
        type: Boolean,
        default: false,
    },
    userInfo: {
        type: Object,
        default: () => { return {} },
    },
});
const form = ref({})
const rules = ref({
    payFee: [{ required: true, message: "请输入收费金额", trigger: "blur" }],
    payCompany: [{ required: true, message: "请输入收费单位", trigger: "blur" }],
    istat: [{ required: true, message: "请选择是否(3+2)", trigger: "change" }],
    reportFileIds: [{ required: true, message: "请上传文件", trigger: "change" }],
    workpaperFileIds: [{ required: true, message: "请上传文件", trigger: "change" }],
    accountFileIds: [{ required: true, message: "请上传文件", trigger: "change" }]}
)
//
const dialogVisible = computed({
    get: () => {
        return props.visible;
    },
    set: (value) => {
        emits("update:visible", value);
    },
});
watch(() => props.visible, value => {
    if (!value) {
        form.value = {}
    } else {
        form.value = Object.assign({}, props.userInfo)
        console.log("🚀 ~ watch ~ form.value:", form.value)
    }
});
// 提交
const handleSubmit = () => {
    proxy.$refs["infoRef"].validate(valid => {
    if (valid) {
      console.log("🚀 ~ submitForm ~ form.value:", form.value)
      const p = JSON.parse(JSON.stringify(form.value))
      if (form.value.reportId != null) {
        updateReport(p).then(response => {
          proxy.$modal.msgSuccess("修改成功");
          emits('finish')
          dialogVisible.value = false
        });
      }
    }
  });
    // emits('finish')
    // dialogVisible.value = false
};
</script>
<style lang="scss" scoped>
@import './index.scss'
</style>